package com.unicomcz.login;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class ChargeDeptAction extends ActionSupport
{
    private String departId;
    
    /**
     * @return the departId
     */
    public String getDepartId()
    {
        return departId;
    }

    /**
     * @param departId the departId to set
     */
    public void setDepartId(String departId)
    {
        this.departId = departId;
    }

    public String execute() throws Exception
    {
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();
        List dis = (List)session.getAttribute("ALLDEPT");
        UserInfo userInfo =  (UserInfo)session.getAttribute("USER_INFO");
        for (int i=0;i<dis.size();i++) {
            DepartInfo di = (DepartInfo)dis.get(i);
            if ((departId!=null)&&(departId.compareTo(di.getDepartId())==0)) {
                userInfo.setDepartCode(di.getDepartCode());
                userInfo.setDepartId(departId);
                userInfo.setDeptName(di.getDepartName());
                userInfo.setQx(di.getQx());
            }
        }
        session.setAttribute("USER_INFO", userInfo);
        return SUCCESS;
    }
    
}
